/**
 * IHIS 1.0 by HoneyBread (김민호, 이충희, 이성연, 신경민)
 * SEP 8기 KAIST
 */
package ihis.tms.server.service;

import java.io.IOException;
import java.net.InetSocketAddress;

import org.apache.mina.common.IoAcceptor;
import org.apache.mina.filter.LoggingFilter;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory;
import org.apache.mina.transport.socket.nio.SocketAcceptor;
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;

/**
 * @author minho kim
 *
 */
public class TmsSocketServer {
	private static int serverPort = 7403;
	
	public static int getServerPort(){
		return TmsSocketServer.serverPort;
	}
	
	public static void setServerPort(int serverPort){
		TmsSocketServer.serverPort = serverPort;
	}
	
	public static void main(String[] args){
		IoAcceptor ioAcceptor = new SocketAcceptor();
		
		SocketAcceptorConfig sac = new SocketAcceptorConfig();
		sac.setReuseAddress(true);
		
		sac.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
		sac.getFilterChain().addLast("logger", new LoggingFilter());
		
		try {
			ioAcceptor.bind(new InetSocketAddress(serverPort), new DefaultServerSessionHandler(), sac);
		} catch (IOException e){
			e.printStackTrace();
		}
		
		
		System.out.println("TMS Server is started... (port:" + serverPort + ")");
	}
	
}
